<html>
<head>
    <script>
        if (!('WebAssembly' in window)) {
            var msg = 'WebAssembly not supported';
            alert(msg);
            console.error(msg);
        }

        let memory = new WebAssembly.Memory({initial: 10, maximum: 100});
        let table = new WebAssembly.Table({initial: 0, element: 'anyfunc'});
        function loadWebAssembly(filename) {
            return fetch(filename)
                .then(response => response.arrayBuffer())
                .then(bytes => WebAssembly.instantiate(bytes, {
                    env: {
                        __linear_memory: memory,
                        __indirect_function_table: table,
                        jsprint: function jsprint(byteOffset) {
                            let s = '';
                            const a = new Uint8Array(memory.buffer);
                            for (let i = byteOffset; a[i]; i++) {
                                s += String.fromCharCode(a[i]);
                            }
                            document.write(s);
                        }
                    }
                }));
        }

        loadWebAssembly('hello.wasm').then(results => {
            const instance = results.instance;
            memory = instance.exports.pagememory;
            console.log(instance.exports);
            instance.exports.helloworld();
        });
    </script>
</head>
<body>
<div id="console"></div>
</body>
</html>